package com.anrongtec.zcpt.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.anrongtec.zcpt.ApiConfig;
import com.anrongtec.zcpt.R;
import com.anrongtec.zcpt.base.BaseActivity;
import com.anrongtec.zcpt.model.Tip;
import com.anrongtec.zcpt.model.TipDataModel;
import com.anrongtec.zcpt.widget.EasyTipDragView;
import com.anrongtec.zcpt.widget.TipItemView;

import java.util.ArrayList;
import java.util.List;

public class DragItemActivity extends BaseActivity {
    private EasyTipDragView easyTipDragView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleShow(false);
        setContentView(R.layout.activity_drag_item);
        initView();
    }

    private void initView() {
        easyTipDragView = (EasyTipDragView) findViewById(R.id.easy_tip_drag_view);
        //设置已包含的标签数据
        easyTipDragView.setAddData(TipDataModel.getAddTips());
        //设置可以添加的标签数据
        easyTipDragView.setDragData(TipDataModel.getDragTips());
        //在easyTipDragView处于非编辑模式下点击item的回调（编辑模式下点击item作用为删除item）
        easyTipDragView.setSelectedListener(new TipItemView.OnSelectedListener() {
            @Override
            public void onTileSelected(Tip entity, int position, View view) {
                List<Boolean> mSelected = easyTipDragView.getDragTipAdapter().getmTextSelected();
                for (int i = 0; i < mSelected.size(); i++) {
                    if (i != position) {
                        easyTipDragView.getDragTipAdapter().getmTextSelected().set(i, false);
                    } else {
                        easyTipDragView.getDragTipAdapter().getmTextSelected().set(i, true);
                    }
                }

                easyTipDragView.getDragTipAdapter().notifyDataSetChanged();
            }
        });
        //设置每次数据改变后的回调（例如每次拖拽排序了标签或者增删了标签都会回调）
        easyTipDragView.setDataResultCallback(new EasyTipDragView.OnDataChangeResultCallback() {
            @Override
            public void onDataChangeResult(ArrayList<Tip> tips) {
                Log.i("heheda", tips.toString());
            }
        });
        //设置点击“确定”按钮后最终数据的回调
        easyTipDragView.setOnCompleteCallback(new EasyTipDragView.OnCompleteCallback() {
            @Override
            public void onComplete(ArrayList<Tip> tips) {
                showToastCustom("最终数据：" + tips.toString(), ApiConfig.SUCCESS);
            }
        });
        easyTipDragView.open();

    }


}
